﻿#define _CRT_SECURE_NO_WARNINGS 1

//编程初学者入门训练第八十六题
//BC88 有序序列插入一个数
//https://www.nowcoder.com/practice/68ae3b28b4a04e098485c4423e2c6548?tpId=107&tqId=33369&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D2%26tpId%3D107%26type%3D107&difficulty=undefined&judgeStatus=undefined&tags=&title=

//和BC77一样的思路

#include<stdio.h>

int main() {
    int n = 0;
    scanf("%d", &n);
    // 开辟数组n+1个空间
    int* arr = (int*)malloc((n + 1) * sizeof(int));
    if (arr == NULL) {
        perror("malloc fail\n");
        return 1;
    }
    //存储数据
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }
    //插入数据
    //找数据位置
    int temp = 0;
    //下标
    int index = 0;
    scanf("%d", &temp);
    for (index = 0; index < n; index++) {
        if (temp < arr[index])
            break;
    }
    //移动数据
    for (int j = n; j > index; j--) {
        arr[j] = arr[j - 1];
    }

    //插入数据
    arr[index] = temp;

    //打印数据
    for (int i = 0; i < n + 1; i++) {
        printf("%d ", arr[i]);
    }
    printf("\n");

    return 0;
}